package cn.stimd.spring.aop.framework;

import org.springframework.util.ClassUtils;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class ProxyFactory extends AdvisedSupport {
    private AopProxyFactory aopProxyFactory = new DefaultAopProxyFactory();
    public ProxyFactory() { }

    public ProxyFactory(Object target) {
        setTarget(target);
        setInterfaces(ClassUtils.getAllInterfaces(target));
    }

    public Object getProxy(){
        return createAopProxy().getProxy();
    }


    /**
     * 将AOP代理的创建委托给工厂对象
     */
    protected final synchronized AopProxy createAopProxy() {
        return this.aopProxyFactory.createAopProxy(this);
    }
}
